fix: safely append beta query for anthropic target URLs #672
Closed
gopkg-dev wants to merge 3 commits intoWei-Shaw:mainfrom
Closed
fix: safely append beta query for anthropic target URLs #672gopkg-dev wants to merge 3 commits intoWei-Shaw:mainfrom
gopkg-dev wants to merge 3 commits intoWei-Shaw:mainfrom
Conversation
Co-authored-by: gopkg-dev <58848833+gopkg-dev@users.noreply.github.com>
Co-authored-by: gopkg-dev <58848833+gopkg-dev@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the gateway’s Anthropic upstream URL construction so beta=true is consistently present when targeting custom Anthropic base URLs, and adjusts passthrough tests to assert the new URL shape.
Changes:
- Added
buildAnthropicTargetURLhelper to append/setbeta=truevia URL parsing. - Updated Anthropic upstream request builders to use the new helper for
/v1/messagesand/v1/messages/count_tokens. - Updated API-key passthrough tests to assert
beta=trueappears in the upstream request URI.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| backend/internal/service/gateway_service.go | Introduces centralized Anthropic target URL builder and switches request builders to use it. |
| backend/internal/service/gateway_anthropic_apikey_passthrough_test.go | Adds assertions that upstream requests include beta=true in the URI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request updates the way our gateway service constructs upstream Anthropic API URLs to ensure the
beta=truequery parameter is always present, regardless of the endpoint or existing query parameters. This change centralizes and standardizes URL construction, reducing the risk of missing or malformed beta flags. Relevant tests have also been updated to verify the new URL structure.URL construction improvements:
buildAnthropicTargetURLingateway_service.goto append or set thebeta=truequery parameter correctly for all Anthropic API requests, handling cases where the endpoint already has query parameters.buildUpstreamRequestAnthropicAPIKeyPassthrough,buildUpstreamRequest,buildCountTokensRequestAnthropicAPIKeyPassthrough,buildCountTokensRequest) to use the new helper for constructing URLs. [1] [2] [3] [4]net/urlto support the new URL construction logic.Test updates:
beta=truequery parameter. [1] [2]